$(function () {
    $("#jqGrid").jqGrid({
        url: '../../sysattachment/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'ID', width: 50, key: true },
			{ label: '外键编码', name: 'fileNo', index: 'FILE_NO', width: 80 }, 	
			{ label: '文件名称', name: 'fileName', index: 'FILE_NAME', width: 80 }, 	
			{ label: '文件大小', name: 'fileSize', index: 'FILE_SIZE', width: 80 },
			{ label: '文件类型', name: 'fileType', index: 'FILE_TYPE', width: 80 }, 
			{ label: '附件类型', name: 'attaType', index: 'ATTA_TYPE', width: 80 }, 	
			{ label: '业务编码', name: 'busiNo', index: 'BUSI_NO', width: 80 }, 	
			{ label: '业务类型', name: 'busiType', index: 'BUSI_TYPE', width: 80 }, 	
			{ label: '创建者', name: 'cdp', index: 'CDP', width: 80 }, 	
			{ label: '创建时间', name: 'cdt', index: 'CDT', width: 80 },
			{ label: '操作', name: 'extField1', index: 'ext_field1', width: 80,
				formatter: function(value, options, row){
					return "<a href='#' onclick='vm.down("+row.id+");'>下载</a>";
			    }
			}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		sysAttachment: {},
		q:{
			fileNo: null , 
			fileName: null , 
			busiNo: null , 
		}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		reset: function() {
			$('#sysAttachmentQuery :input').each(function(){
					$(this).val();
			});
			$('#sysAttachmentQuery').find("select").each(function(){
					$(this).val();
			});						
			vm.q.fileNo = null;
			vm.q.fileName = null;
			vm.q.busiNo = null;
			vm.reload();
		},		
		add: function(){
			vm.sysAttachment = {};
			layer.open({
			    type: 1,  
			    area: ["800px", "600px"],
			    title: "新增",
		        maxmin: true, //开启最大化最小化按钮
		        content: $("#winContent") ,
			    btn: ['确定', '关闭'],
			    yes: function(index, layero){
			    	//$('#fileupload').fileupload('send', {files: filesList});
				},
				cancel: function(index){ 
					
				}
			}); 			
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
            
            updateDialog("修改","winContent","jqGrid","800px","600px");
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.sysAttachment.id == null ? "../../sysattachment/save" : "../../sysattachment/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.sysAttachment),
			    success: function(r){
			    	layer.closeAll();
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../../sysattachment/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../../sysattachment/info/"+id, function(r){
                vm.sysAttachment = r.sysAttachment;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
				postData:vm.q,
                page:page
            }).trigger("reloadGrid");
		},
		down : function(attachId){
			location.href = "/sysattachment/down/"+attachId;
		}
	}
});